<?php $this->load->view('inc/header');?>

<script type="text/javascript" src="<?php echo $static_url;?>xhedit/xheditor-1.1.13-zh-cn.min.js"></script>

<div class="main-cont">
	<h2>添加新闻</h2>
	<form id="frm-news-add" action="admin.php?c=news&m=add_do" method="post"
		isvalidata="true"
		submitbefor="news_add_befor"
	>
	<input type="hidden" value="<?php echo empty($news->id) ? 0 : $news->id;?>" name="id"/>
		<table class="tbl-data" cellpadding="0" cellspacing="0">
			<tr>
				<th width="100">类别：</th>
				<td>
					<?php 
						$cid = empty($news->cid) ? '' : $news->cid;
						$cat_select_tree = empty($cat_select_tree) ? array() : $cat_select_tree;
					?>
					<?php html_select($cat_select_tree,$cid,' name="cid" class="validate[required]" ');?>
				</td>
			</tr>
			<tr>
				<th width="100">新闻标题：</th>
				<td><input class="w2 validate[required]" name="title" value="<?php echo empty($news->title) ? '' : $news->title;?>"/></td>
			</tr>
			<tr>
				<th>新闻内容：</th>
				<td><textarea id="content" class="w3 h1 validate[required]" name="content"><?php echo empty($news->content) ? '' : $news->content;?></textarea></td>
			</tr>
		</table>
		<div class="action">
			<input class="btn-ajax-submit" frmid="frm-news-add" type="button" value="保存" /> 
			<input id="btn-reset" type="reset" value="重置" />
		</div>
	</form>

</div>
<?php $this->load->view('inc/footer');?>

<script>$(function(){
	$('#btn-reset').click();
	$('#content').xheditor({
		tools:'simple',
		upMultiple:true,
		upImgUrl:"<?php echo site_url('c=news&m=upload');?>",
		upImgExt:"jpg,jpeg,gif,png"
	});
});

function news_add_befor($frm){
	var content = $('#content').val(); 
	content = content.replace(/<[^>]*>/g, "");
	
	if(content.length<=0){
		asyncbox.tips('内容不能为空！','error');
		return false;
	} 
	
	return true;
}

</script>
